﻿Imports System.IO

Public Class Insert_Item
    Public nInsertMode As SolidEdgeFramework.RibbonBarInsertMode
    Public sNewName As String

    Private Sub Copy_RB_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles Copy_RB.CheckedChanged
        Label1.Visible = False
        Browse.Visible = False
        Name_Edit.Visible = False

        Display_Listbox_Based_on_RibbonBar_InsertMode()
        nInsertMode = SolidEdgeFramework.RibbonBarInsertMode.seRibbonBarInsertCopy
    End Sub

    Private Sub Move_RB_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles Move_RB.CheckedChanged
        Label1.Visible = False
        Browse.Visible = False
        Name_Edit.Visible = False

        Display_Listbox_Based_on_RibbonBar_InsertMode()
        nInsertMode = SolidEdgeFramework.RibbonBarInsertMode.seRibbonBarInsertMove
    End Sub

    Private Sub Create_RB_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles Create_RB.CheckedChanged
        Label1.Visible = True
        Browse.Visible = True
        Name_Edit.Visible = True

        Display_Listbox_Based_on_RibbonBar_InsertMode()
        nInsertMode = SolidEdgeFramework.RibbonBarInsertMode.seRibbonBarInsertCreate
    End Sub

    Private Function Display_Listbox_Based_on_RibbonBar_InsertMode()

        ' If either of these are checked then they will need to select a group from the list.
        If (Copy_RB.Checked) Or (Move_RB.Checked) Then
            Commands_LB.Visible = True
            Select_LB.Visible = True
        Else
            Commands_LB.Visible = False
            Select_LB.Visible = False
        End If

        ' Using this also to determine the state of the 
        Display_Listbox_Based_on_RibbonBar_InsertMode = Commands_LB.Visible

    End Function

    Private Sub OK_Btn_Click(sender As System.Object, e As System.EventArgs) Handles OK_Btn.Click
        Dim sSelectedItem As String = Nothing


        ' Check the Insert Mode and if they have something selected.
        If (Display_Listbox_Based_on_RibbonBar_InsertMode()) Then
            sSelectedItem = Commands_LB.SelectedItem
            If (sSelectedItem Is Nothing) Then
                ' If they don't have something selected then they either need to select something or press the Cancel button.
                MsgBox("Please either select an item or press the Cancel button.")
                Exit Sub
            End If
        End If

        '  If the Name Edit ctrl is disabled ( when copying / moving a control ) then don't display msg.
        If (Name_Edit.Visible = True) Then
            If (Name_Edit.Text.Trim() <> "") Then
                sNewName = Name_Edit.Text.Trim()
                Me.DialogResult = Windows.Forms.DialogResult.OK
                Me.Dispose()
            Else
                MsgBox("Please enter a new name.")
            End If
        Else
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Dispose()
        End If
    End Sub

    Private Sub Browse_Click(sender As System.Object, e As System.EventArgs) Handles Browse.Click
        Dim filename As String
        OpenFileDialog1.Multiselect = False
        OpenFileDialog1.FileName = ""
        Try
            If OpenFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
                '' Insert code here to process the files.
                For Each filename In OpenFileDialog1.FileNames
                    ' Check to make sure it isn't already in the collection of items.
                    If (filename IsNot Nothing) Then
                        Dim fl As FileInfo = New FileInfo(filename)
                        If (fl.Extension.ToLower = ".exe") Then
                            Name_Edit.Text = fl.FullName
                        Else
                            MsgBox("Please provide a Executable.")
                        End If
                    End If

                Next

            End If

        Catch ex As Exception

        End Try
    End Sub
End Class